package com.imooc.common.lambad;

import org.junit.Test;

import java.util.Arrays;
import java.util.List;
import java.util.function.IntFunction;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
 * Created by deng_wb on 2019/5/12
 */
public class LambadTest {


    public Integer getIndex(List<String> stringList, Predicate<String> predicate){

        for (int i = 0; i < stringList.size(); i++) {
            boolean test = predicate.test(stringList.get(i));
            if (test){
                return i;
            }

        }

        return -1;
    }


    @Test
    public void run1(){

        List<String> stringList = Arrays.asList("a", "b", "c", "d", "e", "f", "g");
        Integer index = getIndex(stringList, string -> string.equals("e"));
        System.out.println(index );
        List<String> e = stringList.stream().limit(index).collect(Collectors.toList());
        System.out.println(e);


    }

}
